'''
Created on May 15, 2012

@author: Vu Dao
'''
from selenium import webdriver
from Interface.articlePage import xpathTitleTxt, xpathAliasTxt,\
    xpathCategoryCombo, xpathStatusCombo, xpathAccessCombo, xpathFeatureCombo,\
    xpathLanguageCombo, xpathArticleText, xpathSaveAndCloseButton
from selenium.webdriver.support.select import Select

# add new article
def addNewArticle(self,articleTitle,articleAlias,articleCategory,articleStatus,articleAccess,articleFeatured,articleLanguage,articleContent):
#    browser = webdriver.Ie()
    browser=self.browser
    # input article title
    element = browser.find_element_by_xpath(xpathTitleTxt())
    element.send_keys(articleTitle)
    # input title alias
    element = browser.find_element_by_xpath(xpathAliasTxt())
    element.send_keys(articleAlias)
    # select article category
    element = browser.find_element_by_xpath(xpathCategoryCombo())
    Select(element).select_by_visible_text(articleCategory)
    # select article Status
    element = browser.find_element_by_xpath(xpathStatusCombo())
    Select(element).select_by_visible_text(articleStatus)
    # select article Access
    element = browser.find_element_by_xpath(xpathAccessCombo())
    Select(element).select_by_visible_text(articleAccess)
    # select article Featured
    element = browser.find_element_by_xpath(xpathFeatureCombo())
    Select(element).select_by_visible_text(articleFeatured)
    # select article Language
    element = browser.find_element_by_xpath(xpathLanguageCombo())
    Select(element).select_by_visible_text(articleLanguage)
    # input article content
    browser.switch_to_frame("jform_articletext_ifr")
#    browser.switch_to_window("tinymce")
    element = browser.find_element_by_xpath(xpathArticleText())
    element.send_keys(articleContent)
    browser.switch_to_default_content()
    # click on Save & Close
    element = browser.find_element_by_xpath(xpathSaveAndCloseButton())
    browser.implicitly_wait(60)
    
